package controler;

import graphics.engine.ProgramShader;

import java.util.Iterator;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;

import mathematics.*;
import mathematics.geometry.PolygonGeometry;

import utils.Point3D;

public class Lasso 
{
	public PolygonGeometry polygon;
	
	public Lasso()
	{
		this.polygon = new PolygonGeometry();
	}
	
	public void begin(Point3D beginPoint)
	{
		this.polygon.clear();
		this.polygon.add(beginPoint);
	}
	
	public void add(Point3D point)
	{
		this.polygon.add(point);
	}
	
	public void end()
	{	
		this.polygon.clear();
	}

	public void Draw(GLAutoDrawable drawable, ProgramShader programShader) 
	{
		GL gl = drawable.getGL();
		Matrix4x4 worldMatrix = new Matrix4x4();		
		worldMatrix.setToIdentity();
		gl.glUniformMatrix4fv(programShader.WorldMatrixUniformID, 1, false, worldMatrix.toFloatArray(), 0);		

		gl.glColor3f(0.0f, 0.0f, 0.0f);	
		gl.glLineWidth(2);
		gl.glBegin(GL.GL_LINE_STRIP);
		for(Iterator<Point3D> it = this.polygon.iterator(); it.hasNext(); )
		{
			Point3D point = it.next();
			gl.glVertex3f((float)point.x(), (float)point.y(), 0.0f);
		}
		gl.glEnd();
	}
}
